<?php
// 处理用户注销信息
// header("content-type:text/html;charset=UTF-8");

include_once("conn.php");

$uid = $_GET['uid'];
$action = $_GET['action'];

if ($action == 'agree') {
    $pic_path = "../public/pic/pet_photos/" . $uid;
    function delFile($pic_path)
    {
        if (!is_dir($pic_path)) {
            return false;
        }
        $files = array_diff(scandir($pic_path), array('.', '..')); // 获取目录下所有文件
        foreach ($files as $file) {
            (is_dir("$pic_path/$file")) ? delFile("$pic_path/$file") : unlink("$pic_path/$file"); // 删除文件
        }
        return rmdir($pic_path); // 删除目录
    }
    if (delFile($pic_path)) {
        echo "<script>alert('图片清空成功！');</script>";
    }
    $del_user = "DELETE FROM user_infos WHERE user_ID ='" . $uid . "'";
    if (mysqli_query($connect_DB, $del_user)) {
        echo "<script>alert('完成注销操作！');location='admin_DealDelAccount.php';</script>";
    } else {
        die("<script>alert('信息删除失败！请重试！');history.go(-1);</script>");
    }
}

if ($action == 'disagree') {
    $update = "UPDATE user_infos SET user_status = '1' WHERE user_ID ='" . $uid . "'";
    if (mysqli_query($connect_DB, $update)) {
        echo "<script>alert('退回申请完成！');location='admin_DealDelAccount.php';</script>";
    } else {
        die("<script>alert('退回申请失败！请重试！');history.go(-1);</script>");
    }
}

$connect_DB->close();
?>